﻿#include "Shader.h"
#include "Utils/CityHash.h"

FGlobalShaderMap* ShaderMap = nullptr;

FShaderRegistration& FGlobalShaderMap::FindOrAddRegistration(size_t InTypeHash)
{
    if (!MapRegistrations.contains(InTypeHash))
    {
        MapRegistrations[InTypeHash] = FShaderRegistration();
    }

    return MapRegistrations.at(InTypeHash);
}

void FGlobalShaderMap::AddShaderContent(uint64_t InShaderHash, Microsoft::WRL::ComPtr<ID3DBlob> InShaderBlob)
{
    MapContent[InShaderHash] = InShaderBlob;
}

void FShaderRegistration::GenerateShaderFileNameHashId()
{
    ShaderFileHashId = CityHash::CityHash64WithSeed(ShaderName.data(), ShaderName.size(), static_cast<uint64_t>(Frequency));
    ShaderFileHashId = CityHash::CityHash64WithSeed(ShaderFilePath.data(), ShaderFilePath.size(), ShaderFileHashId);
    ShaderFileHashId = CityHash::CityHash64WithSeed(Entry.data(), Entry.size(), ShaderFileHashId);
}

uint64_t FShaderRegistration::GetShaderFileNameHashId(int32_t PermutationId) const
{
    check(ShaderFileHashId > 0);
    return ShaderFileHashId;
}

